package config;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.type.AnnotatedTypeMetadata;

import java.util.Map;

/**
 * @BelongsProject: my-product
 * @BelongsPackage: config
 * @Author: wanglf
 * @CreateTime: 2023-06-20  11:38
 * @Description:
 * @Version: 1.0
 */
public class DatabaseTypeCondition implements Condition {

    public boolean matches(ConditionContext conditionContext,
                           AnnotatedTypeMetadata metadata) {
        Map<String, Object> attributes = metadata.getAnnotationAttributes(DatabaseType.class.getName());
        String type = (String) attributes.get("value");
        String enabledDBType = System.getProperty("dbType","MYSQL");
        return (enabledDBType != null && type != null && enabledDBType.equalsIgnoreCase(type));
    }
}